package com.lazy.lib.db;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 数据库里面一些通用的操作
 * 
 * @author luodan
 *
 */
public class DbUtil {

    //获取数据库服务时间
    public final static String GET_DB_SYS_TIME = "select sysdate from dual";
    
    /**
     * 关闭connection，抛异常时不提示
     * @param connection
     */
    public static void closeConnectionInSilence(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException e) {
            }
        }
    }
    
    /**
     * 关闭statement，抛异常时不提示
     * @param statement
     */
    public static void closeStatementInSilence(Statement statement) {
        if (statement != null) {
            try {
                statement.close();
                statement = null;
            } catch (SQLException e) {
            }
        }
    }
    
    /**
     * 关闭result set，抛异常时不提示
     * @param resultSet
     */
    public static void closeResultSetInSilence(ResultSet resultSet) {
        if (resultSet != null) {
            try {
                resultSet.close();
                resultSet = null;
            } catch (SQLException e) {
            }
        }
    }
    
    /**
     * 关闭result set, statement, connection<p>
     * 数据库查询操作，经常需要作这三个关闭操作
     * @param resultSet
     * @param statement
     * @param connection
     */
    public static void closeRS_Statement_ConnInSilence(ResultSet resultSet, Statement statement, Connection connection) {
        closeResultSetInSilence(resultSet);
        closeStatementInSilence(statement);
        closeConnectionInSilence(connection);
    }
   
    /**
     * 关闭statement,connection<p>
     * 数据库存储操作，经常需要作这两个关闭操作
     * @param statement
     * @param connection
     */
    public static void closeStatementAndConnectionInSilence(Statement statement, Connection connection) {
        closeStatementInSilence(statement);
        closeConnectionInSilence(connection);
    }
    
}
